//screen.width  屏幕的宽度   screen.height 屏幕的高度
//window.innerWidth 去除工具条与滚动条的窗口宽度 window.innerHeight 去除工具条与滚动条的窗口高度


import tracker from '../util/tracker';
import onload from '../util/onload';

function getSelector(element) {
    var selector;
    if (element.id) {
        selector = `#${element.id}`;
    } else if (element.className && typeof element.className === 'string') {
        selector = '.' + element.className.split(' ').filter(function (item) { return !!item }).join('.');
    } else {
        selector = element.nodeName.toLowerCase();
    }
    return selector;
}

// 检测白屏的原理就是取屏幕中间的横/纵两条线上的各九个点的元素
export function blankScreen() {
    const wrapperSelectors = ['body', 'html', '#container', '.content'];
    let emptyPoints = 0;
    function isWrapper(element) {
        let selector = getSelector(element);
        if (wrapperSelectors.indexOf(selector) >= 0) {
            emptyPoints++;
        }
    }
    onload(()=>{
        
console.log(122);
        let xElements, yElements;
        for (let i = 1; i < 9; i++) {
            xElements = document.elementsFromPoint(window.innerWidth*i/10,window.innerHeight/2) //获取横坐标上的9个点
            yElements = document.elementsFromPoint(window.innerWidth / 2, window.innerHeight * i / 10) //获取纵坐标上的9个点
            isWrapper(xElements[0]); //获取x轴第一个点
            isWrapper(yElements[0]); //获取y轴第一个点
        }
        if (emptyPoints > 16) {
            let centerElements = document.elementsFromPoint(window.innerWidth / 2, window.innerHeight / 2)
            tracker.send({
                kind: 'stability',
                type: 'blank',
                emptyPoints: "" + emptyPoints,
                screen: window.screen.width + "x" + window.screen.height,
                viewPoint: window.innerWidth + 'x' + window.innerHeight,
                selector: getSelector(centerElements[0]),
            })
        }
    })

}